<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>AI问答系统</title>
    <script src="js/vue-2.4.0.js"></script>
    <script src="js/axios.min.js"></script>
    <style>
        body {
            font-family: 'Arial', sans-serif;
            background-color: #f5f7fa;
            margin: 0;
            padding: 20px;
            color: #333;
        }

        #app {
            max-width: 800px;
            margin: 0 auto;
            background-color: white;
            padding: 30px;
            border-radius: 10px;
            box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
        }

        h1 {
            color: #4285f4;
            text-align: center;
            margin-bottom: 30px;
        }

        textarea {
            width: 100%;
            padding: 12px;
            border: 1px solid #ddd;
            border-radius: 6px;
            font-size: 16px;
            margin-bottom: 15px;
            resize: vertical;
            transition: border 0.3s;
        }

        textarea:focus {
            border-color: #4285f4;
            outline: none;
            box-shadow: 0 0 0 2px rgba(66, 133, 244, 0.2);
        }

        input[type="button"] {
            background-color: #4285f4;
            color: white;
            border: none;
            padding: 12px 25px;
            font-size: 16px;
            border-radius: 6px;
            cursor: pointer;
            transition: background-color 0.3s;
            display: block;
            margin: 0 auto 20px;
        }

        input[type="button"]:hover {
            background-color: #3367d6;
        }

        /* 进度条样式 */
        .progress-container {
            display: none;
            width: 100%;
            background-color: #f1f1f1;
            border-radius: 5px;
            margin: 20px 0;
        }

        .progress-bar {
            width: 0;
            height: 20px;
            background-color: #4285f4;
            border-radius: 5px;
            text-align: center;
            line-height: 20px;
            color: white;
            transition: width 0.4s ease;
        }

        .progress-text {
            text-align: center;
            margin-top: 5px;
            color: #666;
            font-size: 14px;
        }
    </style>
</head>
<body>
<div id="app">
    <h1>AI问答系统</h1>
    <textarea rows="3" placeholder="输入你的问题" v-model="question"></textarea>
    <input type="button" value="提问" @click="getAnswer">

    <!-- 进度条容器 -->
    <div class="progress-container" id="progressContainer">
        <div class="progress-bar" id="progressBar"></div>
        <div class="progress-text">正在搜索中，请等待...</div>
    </div>

    <textarea readonly rows="10" placeholder="AI回答结果" :value="answer"></textarea>
</div>
</body>
<script>
    var vm = new Vue({
        el: "#app",
        data: {
            question: '',
            answer: ''
        },
        methods: {
            getAnswer(){
                if(!this.question.trim()) {
                    alert('请输入问题');
                    return;
                }

                // 显示进度条
                const progressContainer = document.getElementById('progressContainer');
                const progressBar = document.getElementById('progressBar');
                progressContainer.style.display = 'block';
                progressBar.style.width = '0%';

                // 模拟进度条动画
                let progress = 0;
                const interval = setInterval(() => {
                    progress += 5;
                    progressBar.style.width = progress + '%';
                    if(progress >= 95) {
                        clearInterval(interval);
                    }
                }, 200);

                // 发送请求
                axios.get("http://localhost:8080/getAnswer", {
                    params: {
                        keywords: this.question
                    }
                }).then(response=>{
                    clearInterval(interval);
                    progressBar.style.width = '100%';
                    setTimeout(() => {
                        progressContainer.style.display = 'none';
                    }, 500);
                    this.answer = response.data;
                }).catch(function (err){
                    clearInterval(interval);
                    progressContainer.style.display = 'none';
                    alert('请求出错: ' + err);
                });
            }
        },
        mounted(){
        }
    });
</script>
</html>
